/**
 * 
 */

$(document).ready(function () {
	
	var floatWindowLogin = new FloatWindowLogin();
	floatWindowLogin.setLoginSuccessCallBack(function () {
		location.reload();
	});
	
	$("#reload").click(function () {
		$.ajax({
			url: absoluteURL('/system/reload'),
			type: 'json',
			success: function (data) {
				if (data.status == 0) {
					alert('Reload system successful.');
				} else {
					alert(data.error.message);
				}
				location.href = absoluteURL('/');
			}
		});
	});
	
	$('#upload').click(function () {
		$('#upload_file').click();
		return false;
	});
	
	$('#upload_file').change(function () {
		$(this).parent('form').submit();
	});
	
	$('#login').click(function () {
		floatWindowLogin.login();
	});
	
	$('#logout').click(function () {
		$.ajax({
			url: window.webService('/user/logout'),
			type: 'json',
			success: function (data) {
				location.href = absoluteURL('/');
			}
		});
	});
	
	$('#create').click(function () {
		location = absoluteURL('articles/create');
	});
	
	$("code").each(function (index, object) {
		var code = $(object).html();
		code = code.replace("public", "<span style='color: red;'>public</span>");
		code = code.replace("return", "<span style='color: red;'>return</span>");
		code = code.replace(/([\s|\(|\{|;])([A-Z][a-zA-Z0-9_]+)/g, "$1<span style='color: orange;'>$2</span>");
		code = code.replace(/(@\S+)+/, "<span style='color: gray;'>$1</span>");
		$(object).html(code);
	});
});